package accs.model.io;

import java.io.IOException;

import accs.model.UserPasswordPair;

public class MailUserFilter extends UserPasswordReader {
	private UserPasswordReader reader;
	
	public MailUserFilter(UserPasswordReader reader) {
		this.reader=reader;
	}
	
	public UserPasswordPair read() throws IOException {
		UserPasswordPair pair=reader.read();
		if(pair==null) return null;
		
		pair.setUsername(cut(pair.getUsername()));
		return pair;
	}
	
	public static String cut(String mail) {
		int index=mail.indexOf("@");
		if(index!=-1) mail=mail.substring(0,index);
		return mail;
	}

	public void close() throws IOException {
		reader.close();
	}
}